package cn.iocoder.yudao.module.eval.service.filingcreation;

import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.eval.controller.admin.filingcreation.vo.*;
import cn.iocoder.yudao.module.eval.dal.dataobject.filingcreation.FilingCreationDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.eval.dal.mysql.filingcreation.FilingCreationMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
import static cn.iocoder.yudao.module.eval.enums.ErrorCodeConstants.*;

/**
 * 创建备案 Service 实现类
 *
 * @author 龙头企业
 */
@Service
@Validated
public class FilingCreationServiceImpl implements FilingCreationService {

    @Resource
    private FilingCreationMapper filingCreationMapper;

    @Override
    public Long createFilingCreation(FilingCreationSaveReqVO createReqVO) {
        // 插入
        FilingCreationDO filingCreation = BeanUtils.toBean(createReqVO, FilingCreationDO.class);
        // 显式设置deleted字段默认值
        filingCreation.setDeleted(false);
        filingCreationMapper.insert(filingCreation);

        // 返回
        return filingCreation.getId();
    }

    @Override
    public void updateFilingCreation(FilingCreationSaveReqVO updateReqVO) {
        // 校验存在
        validateFilingCreationExists(updateReqVO.getId());
        // 更新
        FilingCreationDO updateObj = BeanUtils.toBean(updateReqVO, FilingCreationDO.class);
        filingCreationMapper.updateById(updateObj);
    }

    @Override
    public void deleteFilingCreation(Long id) {
        // 校验存在
        validateFilingCreationExists(id);
        // 删除
        filingCreationMapper.deleteById(id);
    }

    @Override
        public void deleteFilingCreationListByIds(List<Long> ids) {
        // 删除
        filingCreationMapper.deleteByIds(ids);
        }


    private void validateFilingCreationExists(Long id) {
        if (filingCreationMapper.selectById(id) == null) {
            throw exception(FILING_CREATION_NOT_EXISTS);
        }
    }

    @Override
    public FilingCreationDO getFilingCreation(Long id) {
        return filingCreationMapper.selectById(id);
    }

    @Override
    public PageResult<FilingCreationDO> getFilingCreationPage(FilingCreationPageReqVO pageReqVO) {
        return filingCreationMapper.selectPage(pageReqVO);
    }

}